# 编译器设置
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra
DEBUG_FLAGS = -g -DDEBUG
RELEASE_FLAGS = -O2

# 目录设置
SRC_DIR = src
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj

# 源文件
SOURCES = $(shell find $(SRC_DIR) -name '*.cpp')
OBJECTS = $(SOURCES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
TARGET = $(BUILD_DIR)/gomoku

# 头文件路径
INCLUDES = -I$(SRC_DIR) -I$(SRC_DIR)/board -I$(SRC_DIR)/game -I$(SRC_DIR)/player -I$(SRC_DIR)/ai

# 默认目标
all: $(TARGET)

# 调试版本
debug: CXXFLAGS += $(DEBUG_FLAGS)
debug: $(TARGET)

# 发布版本
release: CXXFLAGS += $(RELEASE_FLAGS)
release: $(TARGET)

# 链接目标文件
$(TARGET): $(OBJECTS)
	@mkdir -p $(BUILD_DIR)
	$(CXX) $(OBJECTS) -o $@

# 编译源文件
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
	@mkdir -p $(dir $@)
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

# 清理
clean:
	rm -rf $(BUILD_DIR)

# 运行
run: $(TARGET)
	./$(TARGET)

.PHONY: all debug release clean run